Ext.namespace("Ext.milan.pagejs.organization.page_orgpermissionmanage");

Ext.milan.pagejs.organization.page_orgpermissionmanage.docLoadBeforeCallBack = function() {
};

Ext.milan.pagejs.organization.page_orgpermissionmanage.docOnReadyCallback = function() {
};

Ext.milan.pagejs.organization.page_orgpermissionmanage.save = function(formID)
{
	var form = $(formID);
	var selects = form.chkper;
	var Msg = "";
	for (i=0; i<selects.length; i++)
	{
		if(selects[i].checked)
		{
			if (selects[i].getAttribute("OrgChecked")==0 && selects[i].getAttribute("PerLV")=="1")
			{
				Msg += selects[i].getAttribute("PerName") + "\n";
			}
		}
	}
	
    Milan.ajaxutility.formSubmit(
    {
        form : formID,
        success : function(response, option)
        {
        	
        }
    });
}

Ext.milan.pagejs.organization.page_orgpermissionmanage.groupChk = function(chkObj)
{
	var form = chkObj.form;
	if(chkObj.checked==true)
	{
		form.sendMaxTO.disabled = false;
		if (form.sendMaxTO.value == "")
			form.sendMaxTO.value = 99;
	}
	else
	{
		form.sendMaxTO.disabled = true;
	}
}

Ext.milan.pagejs.organization.page_orgpermissionmanage.chkClick = function(chkObj)
{
	var form = chkObj.form;
	var tmpObj;
	var selects = form.CompChk;
	for (var i=0; i<selects.length; i++)
	{
		if (selects[i].getAttribute("CompID") == chkObj.getAttribute("CompID")) 
		{
			tmpObj = selects[i];
			break;
		}
	}
	
	selects = form.chkper;
	var trueI =0;
	var falseI = 0;
	for (var i=0; i<selects.length; i++)
	{
		if (selects[i].getAttribute("CompID") == chkObj.getAttribute("CompID"))
		{
			if (selects[i].checked)
				trueI++;
			else
				falseI++;
		}
	}

	if (falseI == 0)
		tmpObj.checked = true;
	else
		tmpObj.checked = false;
}

Ext.milan.pagejs.organization.page_orgpermissionmanage.chkComp = function(chkObj)		//选中模块
{
	var form = chkObj.form;
	var ch = false;
	var i = 0;
	
	if (chkObj.checked)
		ch = true;
	
	var selects = form.chkper;
	var selCount = 0;
	if (selects != null)
	{
		if (selects.length != null) //有两条以上的记录
		{	
			for (i=0; i<selects.length; i++)
			{
				if (selects[i].getAttribute("CompID") == chkObj.getAttribute("CompID"))
					selects[i].checked = ch;
			}
		}
	  	else
		{
			selects.checked = ch;
		}
	}
}

Ext.milan.pagejs.organization.page_orgpermissionmanage.chkAllClick = function(chkObj)
{
	var form = chkObj.form;
	var ch = false;
	var i = 0;
	
	var check=false;
	if(chkObj.value=="全选"){
		chkObj.value="全不选";
		ch=true;
	}else{
		chkObj.value="全选";
	}
	var selects = form.CompChk;
	var selCount = 0;
	if (selects != null)
	{
		if (selects.length != null) //有两条以上的记录
		{	
			for (i=0; i<selects.length; i++)
			{
				selects[i].checked = ch;
				Ext.milan.pagejs.organization.page_orgpermissionmanage.chkComp(selects[i]);
			}
		}
	  	else
		{
			selects.checked = ch;
			Ext.milan.pagejs.organization.page_orgpermissionmanage.chkComp(selects);
		}
	}
	
	var selects = form.group;
	var selCount = 0;
	if (selects != null)
	{
		if (selects.length != null) //有两条以上的记录
		{	
			for (i=0; i<selects.length; i++)
			{
				selects[i].checked = ch;
				Ext.milan.pagejs.organization.page_orgpermissionmanage.groupChk(selects[i]);
			}
		}
	  	else
		{
			selects.checked = ch;
			Ext.milan.pagejs.organization.page_orgpermissionmanage.groupChk(selects);
		}
	}
	
}

Ext.milan.pagejs.organization.page_orgpermissionmanage.showout = function(formID, tableid, isshow)
{
	var form = $(formID);
	var tmpObj = document.getElementById(formID + "table" + tableid);
	var imgObj = document.getElementById(formID + "img" + tableid);
	
	if (tmpObj != null)
	{
		if (isshow != null) 
			if (isshow)
				tmpObj.style.display = "none";
			else
				tmpObj.style.display = "";
						
		if (tmpObj.style.display == "none")
		{
			imgObj.src = Milan.skinType + "images/minus.jpg";
			tmpObj.style.display = "";
		}
		else
		{
			imgObj.src = Milan.skinType + "images/plus.jpg";
			tmpObj.style.display = "none";
		}
	}
}

Ext.milan.pagejs.organization.page_orgpermissionmanage.expandall = function(btnobj)
{
	var complength = btnobj.form.complength.value;
	var checked = false;
	if (btnobj.value=="全部展开"){
		btnobj.value = "全部收缩";
		checked =true;
	}else{
		btnobj.value="全部展开"
	}
	for (i=0; i<complength; i++)
		Ext.milan.pagejs.organization.page_orgpermissionmanage.showout(btnobj.form.id, i, checked);
}

Ext.milan.pagejs.organization.page_orgpermissionmanage.hideWin = function()
{
	if(win)
	    win.closeDialog()
}
Ext.milan.pagejs.organization.page_orgpermissionmanage.backUserList = function(obj)
{
	url = "user/list.do";
	Milan.pagejs.page_index.updateCurrentTabByUrl(url);
}
Ext.milan.pagejs.organization.page_orgpermissionmanage.backGroupList = function(obj)
{
	url = "group/list.do";
	Milan.pagejs.page_index.updateCurrentTabByUrl(url);
}
Ext.milan.pagejs.organization.page_orgpermissionmanage.backDeptList = function(obj)
{
	url = "dept/manager.do";
	Milan.pagejs.page_index.updateCurrentTabByUrl(url);
}